#测试博客列表界面
import time
from selenium.webdriver.common.by import By
from Common.Untils import BlogDriver


class BlogList:
    url=""
    driver=""
    def __init__(self):
        self.url="http://8.137.19.140:9090/blog_list.html"
        self.driver=BlogDriver.driver
        self.driver.get(self.url)

    #登陆状态
    def ListByLogin(self):
        #个人信息模块
        #检查头像和昵称
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > img")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #检查“分类”标签，和标签下数字
        actual = self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)").text
        assert actual == "分类"
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(5) > span:nth-child(2)")
        #检查“文章”标签
        actual=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)").text
        assert actual=="文章"
        #检查gitub地址标签
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > a")
        #文章列表模块
        #标题
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.title")
        #时间
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.date")
        #检查统计数量是否与列表实际文章数量一致
        num=self.driver.find_elements(By.CSS_SELECTOR,"body > div.container > div.right > div")
        ret=self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)").text
        #assert len(num)==ret
        print(len(num))
        print(ret)
        #点击“查看全文”按钮，跳转到文章详情页
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a").click()
        self.driver.back()
        #菜单栏模块
        #点击“主页”，检查昵称，是否跳转到列表页
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(4)").click()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")
        #点击“写博客”，检查发布按钮，是否跳转到博客编辑页
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(5)").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit")
        #点击注销按钮取消登陆状态，返回到登陆页面
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
    #未登录状态
    def ListByNotlogin(self):
        #未登录状态下无法跳转到列表页，仍在登陆页面
        self.driver.get(self.url)
        self.driver.find_element(By.CSS_SELECTOR,"#submit")

# List=BlogList()
# List.ListByLogin()
# List.ListByNotlogin()

